package com.dgut.legalservice.dao;

import com.dgut.legalservice.domain.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface IUser {   //用户表dao层接口

    @Insert("insert into t_sys_user(loginName,password,realName,sex,type,status)values(#{loginName}," +
            "#{password},#{realName},#{sex},'普通用户','正常')")   //添加普通用户账户
    public int addNormalUser(User User);

    @Insert("insert into t_sys_user(loginName,password,realName,phoneNum,email,type,status)values(#{loginName}," +
            "#{password},#{realName},#{phoneNum},#{email},'律师','正常')")  //添加律师
    public int addLawUser(User User);

    @Insert("insert into t_sys_user(loginName,password,realName,phoneNum,email,type,status)values(#{loginName}," +
            "#{password},#{realName},#{phoneNum},#{email},'管理员','正常')") //添加管理者
    public int addManager(User User);

    @Insert("insert into t_sys_user(loginName,password,realName,phoneNum,email,type,status,photoAttId)values(#{loginName}," +
            "#{password},#{realName},#{phoneNum},#{email},#{type},'正常',#{photoAttId})") //添加用户
    public int addUser(User user);
    @Insert("insert into t_sys_user(loginName,password,birthday,realName,email,type,status,photoAttId)values(#{loginName}," +
            "#{password},#{birthday},#{realName},#{email},#{type},'正常',#{photoAttId})") //添加用户
    public int insertUser(User user);   //用户注册时调用，没有手机号

    @Update("update t_sys_user set photoAttId=#{photoAttId} where loginName=#{loginName}")  //根据登录名更新头像
    public void updateHead(User user);

    @Update("update t_sys_user set realName=#{realName},sex=#{sex},birthday=#{birthday}," +
            "address=#{address} where loginName=#{loginName}")  //根据登录名修改普通用户基础信息
    public void updateNormalBase(User user);


    @Update("update t_sys_user set loginName=#{loginName},password=#{password},realName=#{realName},sex=#{sex}," +
            "phoneNum=#{phoneNum},email=#{email} where id=#{id}")
    public void updateNormal(User user);  //普通用户信息更新


    //用户修改密码
    @Update("update t_sys_user set password = #{password} where loginName = #{loginName}")
    public void updatePassword(User user);

    @Update("update t_sys_user set email = #{email} where loginName = #{loginName}")
    public void updateEmail(User user);
    //服务商更改公司信息
    @Update("update t_sys_user set lawyerNum = #{lawyerNum} ,telNum = #{telNum} ,legalOrg= #{legalOrg} ,nowPosition= #{nowPosition} " +
            ",serviceYear= #{serviceYear}  where loginName = #{loginName}")
    public void updateCompanyInfo(User user);
    //前台普通用户修改基本信息
    @Update("update t_sys_user set realName = #{realName},sex=#{sex},email=#{email},address=#{address}," +
            "question=#{question},answer=#{answer},birthday=#{birthday},postNum=#{postNum},type=#{type}," +
            "idCardNum=#{idCardNum},phoneNum=#{phoneNum},intro=#{intro},photoAttId=#{photoAttId} where loginName = #{loginName}")
    public void updateNorUser(User user);

    //后台管理，超级管理员信息更改
    @Update("update t_sys_user set realName = #{realName},sex=#{sex},email=#{email},type=#{type},phoneNum=#{phoneNum},photoAttId=#{photoAttId}" +
            " where loginName = #{loginName}")
    public void updateSuper(User user);

    //后台管理，修改账号信息
    @Update("update t_sys_user set realName = #{realName},type=#{type},password=#{password},phoneNum=#{phoneNum},email=#{email}" +
            " where id = #{id}")
    public void editUser(User user);
    //后台管理，冻结账号
    @Update("update t_sys_user set status ='停用' where id = #{id}")
    public void ice(Integer id);
    //后台管理，解冻账号
    @Update("update t_sys_user set status ='正常' where id = #{id}")
    public void unIce(Integer id);
    //后台管理，重置密码
    @Update("update t_sys_user set password=#{password} where id = #{id}")
    public void resetPwdById(Integer id,String password);

    @Select("select * from t_sys_user where type!='超级管理员'")
    public List<User> findNotSuper();   //查询非超级管理员的所有用户
    @Select("select * from t_sys_user where type!='超级管理员' and type!='管理员'")
    public List<User> findNormal();   //查询非超级管理员\管理员的所有用户



    @Select("select * from t_sys_user where realName=#{realName} and type=#{type}")
    public List<User> findByNameAndType(@Param(value = "realName") String realName,@Param(value = "type") String type);   //根据真实姓名和用户类型查询账号
    @Select("select * from t_sys_user where realName=#{realName}")
    public List<User> findByRealName(String realName);   //根据真实姓名查询账号
    @Select("select * from t_sys_user where type=#{type}")
    public List<User> findByType(String type);   //根据用户类型查询账号

    @Select("select * from t_sys_user where type='普通用户'")
    public List<User> findAllNormal();

    @Select("select photoAttId from t_sys_user where loginName=#{loginName}")
    public String findPhotoAttId(String loginName);

    @Select("select * from t_sys_user where loginName=#{loginName}")
    public User findByLoginName(String loginName);

    @Select("select * from t_sys_user where type='管理员'")
    public List<User> findManager();

    @Select("select * from t_sys_user where id = #{id}")
    public User findById(Integer id);

    @Delete("delete from t_sys_user where id=#{id}")
    public void deleteUser(Integer id);

//登录注册板块************************************************
    @Select("select * from t_sys_user where email = #{email}")
    public User findByEmail(String email);
//忘记密码找回密码
    @Select("select question from t_sys_user where loginName = #{loginName}")
    public String findQuestion(String loginName);
    @Select("select answer from t_sys_user where loginName = #{loginName}")
    public String findAnswer(String loginName);

}
